<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="Flatfy Free Flat and Responsive HTML5 Template ">
    <meta name="author" content="">
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/h-ui.admin/css/style.css"/>
    <script src="/static/js/result.js"></script>
    <style>
        .toTop {
            position: fixed;
            bottom: 10px;
            right: 40px;
            z-index: 999;
            display: none;
            font-size: 16px;
            cursor: pointer;
            overflow: hidden;
            visibility: visible;
            background-color: #fff;
            border: 1px solid #d9bc96;
            color: #9c9c9c;
            font-size: 16px;
            width: 50px;
            height: 50px;
            line-height: 38px;
            text-align: center;
            text-decoration: none;
            _position: absolute;
        }
        .toTop:hover{ color:#fff; text-decoration:none; background-color: #847d99
        }
    </style>
    <title>签到结果查询</title>

    <!--导出excel表格-->
    <script>
        var idTmr;
        function  getExplorer() {
            var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
            var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
            var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
            var isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") > -1 && !isIE; //判断是否IE的Edge浏览器
            var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
            var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") == -1; //判断是否Safari浏览器
            var isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("Safari") > -1; //判断Chrome浏览器

            //ie
            if (isIE || !!window.ActiveXObject || "ActiveXObject" in window) {
                return 'ie';
            }
            //firefox
            else if (isFF) {
                return 'Firefox';
            }
            //Chrome
            else if(isChrome){
                return 'Chrome';
            }
            //Opera
            else if(isOpera){
                return 'Opera';
            }
            //Safari
            else if(isSafari){
                return 'Safari';
            }
        }
        function export_excel(tableid) {
            if(getExplorer()=='ie'){
                var curTbl = document.getElementById(tableid);
                var oXL;
                try {
                    oXL = new ActiveXObject("Excel.Application"); //创建AX对象excel
                } catch (e) {
                    alert("无法启动Excel!\n\n如果您确信您的电脑中已经安装了Excel，" + "那么请调整IE的安全级别。\n\n具体操作：\n\n" + "工具 → Internet选项 → 安全 → 自定义级别 → 对没有标记为安全的ActiveX进行初始化和脚本运行 → 启用");
                    return false;
                }

                var oWB = oXL.Workbooks.Add();
                var oSheet = oWB.ActiveSheet;
                var Lenr = curTbl.rows.length;
                for (i = 0; i < Lenr; i++) {
                    var Lenc = curTbl.rows(i).cells.length;
                    for (j = 0; j < Lenc; j++) {
                        oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;
                    }
                }
                oXL.Visible = true;
            }else{
                tableToExcel(tableid)
            }
        }
        function Cleanup() {
            window.clearInterval(idTmr);
            CollectGarbage();
        }
        var tableToExcel = (function() {
            var uri = 'data:application/vnd.ms-excel;base64,',
                template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
                base64 = function(s) {
                    return window.btoa(unescape(encodeURIComponent(s)))
                },
                // 下面这段函数作用是：将template中的变量替换为页面内容ctx获取到的值
                format = function(s, c) {
                    return s.replace(/{(\w+)}/g,
                        function(m, p) {
                            return c[p];
                        }
                    )
                };
            return function(table, name) {
                if (!table.nodeType) {
                    table = document.getElementById(table)
                }
                // 获取表单的名字和表单查询的内容
                var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML};
                // format()函数：通过格式操作使任意类型的数据转换成一个字符串
                // base64()：进行编码
                window.location.href = uri + base64(format(template, ctx))
            }
        })()

    </script>


    <!--获取教师姓名名单-->
    <script>
        $(document).ready(function () {
            $.ajax({
                type: "get",
                url: "/teacherList",
                async:true,
                success: function (teacherList) {
                    var teacherSelect = document.getElementById("teacherName");
                    if (teacherList != null) {
                        for (var i = 0; i < teacherList.length; i++) {
                            //遍历后台传回的结果，一项项往select中添加option
//                            console.log(teacherList[i]);
                            teacherSelect.options.add(new Option(teacherList[i], teacherList[i]));
                        }
                    }
                },
                error: function () {
                    alert('Error');
                }
            })

        });
    </script>
    <!--自动获取所有签到信息-->
    <script>
        $(document).ready(function () {
            $.ajax({
                type: "get",
                url: "/allresult",
                dataType: 'json',
                success: function (signResult) {
                    var Data_list = signResult["allSignIner"];
                    $(".r strong").append(Data_list.length);
                    for (var i = 0; i < Data_list.length; i++) {
                        if (Data_list[i]["status"] == null) {
                            var status = "已签到"
                        }

                        $(".signer").append("<tr class=\"text-c\"><td><input type=\"checkbox\" value=\"\" name=\"\"></td><td>" + Data_list[i]["stuId"] + "</td><td>" + Data_list[i]["name"] + "</td><td>" + Data_list[i]["teacherName"] + "</td><td>" + formatTime(Data_list[i]["signTime"]) + "</td><td>" + Data_list[i]["ipAddr"] + "</td><td>" + status + "</td></tr>");
                    }

                },
                error: function () {
                    alert('Error');
                }
            })
        });
    </script>
    <!--匹配时间-->
    <script>
        function formatTime(time) {
            var d = new Date(time);

            var times = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
//            var signTime = format(times);
            return times;
        }
    </script>
    <!--教师查询-->
    <script>
        function showResult() {
            $(".signer").remove();
//            $(".text-c").remove();

            var teacherName = $('#teacherName').val();
            var classDate = $('#classDate').val();
            var classTime = $('#classTime').val();
            var times = $('#times').val();
            if (teacherName == 0) {
                $.ajax({
                    type: "get",
                    url: "/allresult",
                    dataType: 'json',
                    success: function (signResult) {
                        var Data_list = signResult["allSignIner"];
                        $(".r strong").text(Data_list.length);
                        $(".titl").after("<tbody class=\"signer\"></tbody>");
                        for (var i = 0; i < Data_list.length; i++) {

                            $(".signer").append("<tr class=\"text-c\"><td><input type=\"checkbox\" value=" + Data_list[i]["id"] + " name=\"\"></td><td>" + Data_list[i]["stuId"] + "</td><td>" + Data_list[i]["name"] + "</td><td>" + Data_list[i]["teacherName"] + "</td><td>" + formatTime(Data_list[i]["signTime"]) + "</td><td>" + Data_list[i]["ipAddr"] + "</td><td>" + Data_list[i]["status"] + "</td></tr>");
                        }


                    },
                    error: function () {
                        alert('Error');
                    }
                })
            } else {
                $.ajax({
                    type: "post",
                    url: "/resultsub",
                    dataType: 'json',
                    data: {
                        'teacherName': teacherName,
                        'classDate': classDate,
                        'classTime': classTime,
                        'times': times
                    },
                    success: function (signResult) {
                        console.log(signResult);

                        var Data_list = signResult["signIner"];
//                        document.getElementsByTagName("strong").innerText = Data_list.length;
//                        $(".r strong").remove(Data_list.length);
                        $("#count").text(Data_list.length);
                        $(".titl").after("<tbody class=\"signer\"></tbody>");
                        for (var i = 0; i < Data_list.length; i++) {


                            $(".signer").append("<tr class=\"text-c\"><td><input type=\"checkbox\" value=" + Data_list[i]["id"] + " name=\"\"></td><td>" + Data_list[i]["stuId"] + "</td><td>" + Data_list[i]["name"] + "</td><td>" + Data_list[i]["teacherName"] + "</td><td>" + formatTime(Data_list[i]["signTime"]) + "</td><td>" + Data_list[i]["ipAddr"] + "</td><td>" + Data_list[i]["status"] + "</td></tr>");
                        }

                    },
                    error: function () {
                        alert('Error');
                    }
                })

            }


        };
    </script>
    <!--学生查询-->
    <script>
        function getUserResult() {
            $(".signer").remove();
            var stuName = $('#stuName').val();
            $.ajax({
                type: "post",
                url: "/userResultsub",
                dataType: 'json',
                data: {
                    'stuName': stuName
                },
                success: function (signResult) {
                    var Data_list = signResult["userResult"];
                    $("#count").text(Data_list.length);
                    $(".titl").after("<tbody class=\"signer\"></tbody>");
                    for (var i = 0; i < Data_list.length; i++) {
                        $(".signer").append("<tr class=\"text-c\"><td><input type=\"checkbox\" value=" + Data_list[i]["id"] + " name=\"\"></td><td>" + Data_list[i]["stuId"] + "</td><td>" + Data_list[i]["name"] + "</td><td>" + Data_list[i]["teacherName"] + "</td><td>" + formatTime(Data_list[i]["signTime"]) + "</td><td>" + Data_list[i]["ipAddr"] + "</td><td>" + "已签到" + "</td></tr>");
                    }

                },
                error: function () {
                    alert('Error');
                }
            })
        }
    </script>
    <script type="text/javascript" src="/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont" >&#xe67f;</i><a href="/index">首页</a> </i><span class="c-gray en">&gt;</span></i><i class="Hui-iconfont">&#xe627;</i> 签到结果查询

    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont" >&#xe68f;刷新</i></a>
</nav>
<div class="page-container">
    <div class="text-c">

        学生姓名：
        <input type="text" class="input-text" id="stuName" name="" style="width:150px">
        <!--查询按钮-->
        <input type="hidden" name="">
        <button onclick="getUserResult()" class="btn btn-primary radius" id="studentRefer" name="">
            <i class="Hui-iconfont">&#xe600;</i>查询
        </button>


        &nbsp;&nbsp;&nbsp;&nbsp;
        教师姓名:
        <span class="select-box inline">
            <select class="select" id="teacherName" name="">
                <option value="0">选择教师姓名</option>
            </select>
		</span>

        &nbsp;&nbsp;&nbsp;&nbsp;
        上课日期：
        <span class="select-box inline">
            <input type="date" id="classDate" value=""/>
        </span>


        &nbsp;&nbsp;&nbsp;&nbsp;
        上课时间：
        <span class="select-box inline">
            <select class="select" id="classTime" name="">
                <option value="0">选择一个上课时间</option>
                <option value="1">第一节</option>
                <option value="2">第二节</option>
                <option value="3">第三节</option>
                <option value="4">第四节</option>
            </select>
        </span>

        &nbsp;&nbsp;&nbsp;&nbsp;
        点名次数:
        <span class="select-box inline">
            <select class="select" id="times" name="">
                <option value="0">选择本次课程点名次数</option>
                    <option value="1">一次</option>
                    <option value="2">两次</option>
                    <option value="3">三次</option>
                    <option value="4">四次</option>
            </select>
		</span>

        &nbsp;&nbsp;&nbsp;&nbsp;
        <!--查询按钮-->

        <input type="hidden" name="">
        <button onclick="showResult()" class="btn btn-primary radius" id="teacherRefer" name=""><i class="Hui-iconfont">&#xe600;</i>查询
        </button>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <button class="btn btn-success radius" onclick="export_excel('tableExcel')" type="button" value="" style="">
            ☞导出至Excel表格
        </button>
    </div>


    <div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
		<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
		</span>
        <span class="r">共有数据：<strong id="count"></strong> 条</span>
    </div>

    <div class="mt-20">
        <table id="tableExcel" class="table table-border table-bordered table-bg table-hover table-sort">
            <thead class="titl">
            <tr class="text-c">
                <th width="25"><input type="checkbox" name="" value=""></th>
                <th width="100">学生学号</th>
                <th width="100">学生姓名</th>
                <th width="100">教师姓名</th>
                <th width="100">签到时间</th>
                <th width="100">IP地址</th>
                <th width="100">上课状态</th>
            </tr>
            </thead>


            <tbody class="signer">

            </tbody>

        </table>


    </div>
</div>
<!--<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>-->
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>
<script>

    $(function(){
        $(window).on("scroll",backToTopFun);
        backToTopFun()});


    var $backToTopEle=$('<a href="javascript:void(0)" class="Hui-iconfont toTop" title="返回顶部" alt="返回顶部" style="display:none">&#xe684;</a>').appendTo($("body")).click(function(){
        $("html, body").animate({ scrollTop: 0 }, 120);
    });
    var backToTopFun = function() {
        var st = $(document).scrollTop(), winh = $(window).height();
        (st > 0)? $backToTopEle.show(): $backToTopEle.hide();
        /*IE6下的定位*/
        if(!window.XMLHttpRequest){
            $backToTopEle.css("top", st + winh - 166);
        }
    };
</script>

</body>
</html>